package web.login.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import web.login.bo.NewUserAjaxBo;
import web.login.entity.Login;

@Controller
public class CreateUserAjaxController 
{
	private final Log log = LogFactory.getLog(CreateUserAjaxController.class);
	
	@Autowired
	private NewUserAjaxBo newUserAjaxBo;
	
	
	public NewUserAjaxBo getNewUserAjaxBo() {
		return newUserAjaxBo;
	}


	public void setNewUserAjaxBo(NewUserAjaxBo newUserAjaxBo) {
		this.newUserAjaxBo = newUserAjaxBo;
	}


	@RequestMapping(value="/createUser.htm",method = RequestMethod.POST)
	public ModelAndView onSubmit(HttpServletRequest request) {
		log.info("Inside onSubmit of AJAX Controller...");
		String firstName = request.getParameter("fname")!=null?(String)request.getParameter("fname"):"";
		String lastName = request.getParameter("lname")!=null?(String)request.getParameter("lname"):"";
		String email = request.getParameter("email")!=null?(String)request.getParameter("email"):"";
		log.info("First Name : "+firstName+"Last Name : "+lastName);
		log.info("Email : "+email);
		Login login = new Login();
		login.setFirstName(firstName);
		login.setLastName(lastName);
		login.setUserRole(email);
		this.newUserAjaxBo.createUser(login);
		return new ModelAndView("welcome");
	}
	
	
}
